package com.xinghanlaser.applet.points;

import com.xinghanlaser.applet.base.flow.core.BasePoint;
import com.xinghanlaser.applet.entity.TopicHandleDetail;
import com.xinghanlaser.applet.service.ITopicHandleDetailService;
import com.xinghanlaser.applet.service.ITopicHandleHistoryService;
import com.xinghanlaser.applet.service.ITopicService;
import com.xinghanlaser.applet.vo.point.DeliveryVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * <p>
 *
 * <p>
 *
 * @author: mftuo 陀铭峰
 * @since: 2024/5/30 14:41
 */
@Component
public class DeliveryPoint extends BasePoint<DeliveryVO> {
    @Resource
    private ITopicService topicService;

    @Resource
    private ITopicHandleDetailService handleService;

    @Resource
    private ITopicHandleHistoryService historyService;

    @Override
    protected void pointOperation(DeliveryVO vo) {
        final Long topicId = vo.getTopicId();

        // 校验申请单是否存在
        topicService.validatedTopicId(topicId);

        // 更新处理流程信息
        TopicHandleDetail handleEntity = topicService.getHandleEntityByTopicId(topicId);
        handleEntity.setCurrentPointId(getPointId());
        handleService.updateById(handleEntity);

        // 保存历史流程信息
        historyService.saveHistory(
                handleEntity.getId(),
                getPointId(),
                "已发货，物流单号：" + vo.getLogisticsNum(),
                vo.getLogisticsNum()
        );
    }

    @Override
    protected Class<DeliveryVO> getPointDataType() {
        return DeliveryVO.class;
    }

    @Override
    public Long getPointId() {
        return 12L;
    }
}
